Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
Cant stop the flow of a loop | Javascript

Im trying return an int that count the last Zeros of an int, but I can´t to stop the flow of the loop when it finds something that is not zero. whats wrong?

const endZeros = (value) => {
  const stringValue = `${value}`
  const arrValue = stringValue.split("").reverse()
  let total = 0;
  arrValue.map(el => {
    if (el === "0") {
      total = total + 1
    } else {
      return // I check return false too (and true, and all! --> desesperation)
    }
  })
  return total;
}

endZeros(100100)

Thank You, everyone ❤️

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about a simple regexp?

const lastZeros = num => { const zeros = String(num).match(/0+$/); return zeros ? zeros[0].length : 0 };

console.log(lastZeros(100100))
console.log(lastZeros(111111))
console.log(lastZeros(101000))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!